﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Batalha_Estelar
{
    public class GameState
    {
        public List<GameObject> GameObjects { get; protected set; }

        public GameState()
        {
            GameObjects = new List<GameObject>();
        }

        public bool IsGameOver()
        {
            //obter jogadores
            var players = GameObjects.OfType<PlayerShip>();

            //Tem algum jogador com vida?
            var gameOver = !players.Any((x) => x.Lifes >= 0);

            return gameOver;
        }

        public IQueryable<GameObject> Query()
        {
            return GameObjects.AsQueryable();
        }

        public void Add(GameObject obj)
        {
            GameObjects.Add(obj);
        }

        public bool Remove(GameObject obj)
        {
            return GameObjects.Remove(obj);
        }

        public int RemoveAll(Predicate<GameObject> match)
        {
            return GameObjects.RemoveAll((x) => match.Invoke(x));
        }

        public void Clear()
        {
            GameObjects.Clear();
        }

    }
}
